package com.letoken.platform.repo.ecommerce.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.pub.req.PageData;
import com.letoken.platform.repo.ecommerce.dto.ShopFreezeReq;
import com.letoken.platform.repo.ecommerce.po.EcommerceFreezeHistory;
import com.letoken.platform.repo.ecommerce.vo.ShopFreezeDetailRes;
import com.letoken.platform.repo.ecommerce.vo.ShopFreezeRes;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 电商冻结流水 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2023-09-19
 */
public interface EcommerceFreezeHistoryMapper extends BaseMapper<EcommerceFreezeHistory> {



    @Select("select id,type,ABS(amount) as amount,create_time from ecommerce_freeze_history where user_id = #{req.userId} and amount_cap=0 order by create_time  desc ")
    Page<ShopFreezeRes> freezeList(@Param("page") Page<ShopFreezeRes> page , @Param("req") ShopFreezeReq req);

    @Select("select id,type,ABS(amount_cap) as amount,create_time from ecommerce_freeze_history where user_id = #{req.userId} and amount_cap != 0 order by create_time  desc ")
    Page<ShopFreezeRes> freezeListCap(@Param("page") Page<ShopFreezeRes> page , @Param("req") ShopFreezeReq req);

    @Select("select h.id , h.type, ABS(h.amount) as amount,o.order_no ,h.create_time , a.update_time,a.type as afterType from ecommerce_freeze_history h inner join ecommerce_user_order o on h.order_id = o.id left join ecommerce_after_order a on h.after_id = a.id where h.id = #{id} and  h.user_id = #{userId}")
    ShopFreezeDetailRes freezeDetail(@Param("id") Integer id,@Param("userId") Integer userId);
}
